// import api from '../../utils/api';
export default{
    //过滤传参数据
    pipeData(str){
        return str;
    },
    //格式时间函数
    format:function(time){
        var t = new Date(time);
        var year = t.getFullYear();
        var month = (t.getMonth()+1);
        var day = t.getDate();
        var hour = t.getHours();
        var minute = t.getMinutes();
        var second = t.getSeconds();
        if(month<10){
            month = "0"+month;
        }
        if(day<10){
            day = "0"+day;
        }
        if(hour<10){
          hour = "0"+hour;
        }
         if(minute<10){
          minute = "0"+minute;
        }
         if(second<10){
          second = "0"+second;
        }
        if(hour =="00" && minute == "00" && second == "00"){
          return t = year+"-"+month+"-"+day;
        }else{
          return t = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
        }
        
    },
    //日期，在原有日期基础上，增加days天数
    addDate(date, days) {
        var dates = new Date(date);
        dates.setDate(dates.getDate() + days);
        var month = dates.getMonth() + 1;
        var day = dates.getDate();
        var mm = "'" + month + "'";
        var dd = "'" + day + "'";
        //单位数前面加0
        if(mm.length == 3) {
            month = "0" + month;
        }
        if(dd.length == 3) {
            day = "0" + day;
        }
        var time = dates.getFullYear() + "-" + month + "-" + day
        return time;
    },
    formatData(date) {
        if(typeof date == 'object'){
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? '0' + m : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            return y + '-' + m + '-' + d;
        }
            return date;    
    },
     //上一页
     prevPage(page,num,dis1,dis2,total,fn){
        this[page]--;
        if(this[page]<=1){
          this[dis1]=true;

        }
        if(this[page] < Math.ceil(total/num)){
          this[dis2]=false;
        }
        fn();
    },
    //下一页
    nextPage(page,num,dis1,dis2,total,fn){
        this[page]++;
        if(this[page]>1){
          this[dis1]=false;
        }  
        if(this[page] == Math.ceil(total/num)){
            this[dis2]=true;
            this.$message({
                message:"这是最后一页了",
                type:"warning"
            });
            return;
        }
        fn();
    },
}